package com.zrl.ggkt.live.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrl.ggkt.live.service.LiveCourseAccountService;
import com.zrl.ggkt.live.service.LiveCourseService;
import com.zrl.ggkt.model.live.LiveCourse;
import com.zrl.ggkt.model.live.LiveCourseAccount;
import com.zrl.ggkt.result.R;
import com.zrl.ggkt.vo.live.LiveCourseConfigVo;
import com.zrl.ggkt.vo.live.LiveCourseFormVo;
import com.zrl.ggkt.vo.live.LiveCourseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 直播课程表 前端控制器
 * </p>
 *
 * @author zrl
 * @since 2022-08-21
 */
@RestController
@RequestMapping("/admin/live/liveCourse")
public class LiveCourseController {

    @Autowired
    private LiveCourseService liveCourseService;

    @Autowired
    private LiveCourseAccountService liveCourseAccountService;


    @GetMapping("{page}/{limit}")
    public R list(@PathVariable Long page, @PathVariable Long limit){
        Page<LiveCourse> pageInfo = new Page<>(page, limit);
        IPage<LiveCourse> pageModel = liveCourseService.selectPage(pageInfo);
        return R.ok(pageModel);
    }

    @ApiOperation(value = "新增")
    @PostMapping("save")
    public R save(@RequestBody LiveCourseFormVo liveCourseVo) {
        liveCourseService.save(liveCourseVo);
        return R.ok();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable Long id) {
        liveCourseService.removeLive(id);
        return R.ok();
    }

    //根据id查询直播课程基本信息
    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public R<LiveCourse> get(@PathVariable Long id) {
        LiveCourse liveCourse = liveCourseService.getById(id);
        return R.ok(liveCourse);
    }

    //根据id查询直播课程基本信息和详细信息
    @ApiOperation(value = "获取")
    @GetMapping("getInfo/{id}")
    public R<LiveCourseFormVo> getInfo(@PathVariable Long id) {
        LiveCourseFormVo liveCourseFormVo = liveCourseService.getLiveCourseFormVo(id);
        return R.ok(liveCourseFormVo);
    }

    //修改直播课程信息
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public R updateById(@RequestBody LiveCourseFormVo liveCourseFormVo) {
        liveCourseService.updateLiveById(liveCourseFormVo);
        return R.ok();
    }



    //获取直播账户信息
    @ApiOperation(value = "获取直播账户信息")
    @GetMapping("getLiveCourseAccount/{id}")
    public R<LiveCourseAccount> getLiveCourseAccount(@PathVariable Long id) {
        LiveCourseAccount liveCourseAccount = liveCourseAccountService.getByLiveCourseAccountId(id);
        return R.ok(liveCourseAccount);
    }

    //获取直播配置信息
    @ApiOperation(value = "获取直播配置信息")
    @GetMapping("getCourseConfig/{id}")
    public R getCourseConfig(@PathVariable Long id) {
        LiveCourseConfigVo liveCourseConfigVo = liveCourseService.getCourseConfig(id);
        return R.ok(liveCourseConfigVo);
    }

    @ApiOperation(value = "修改配置")
    @PutMapping("updateConfig")
    public R updateConfig(@RequestBody LiveCourseConfigVo liveCourseConfigVo) {
        liveCourseService.updateConfig(liveCourseConfigVo);
        return R.ok();
    }

    @ApiOperation(value = "获取最近的直播")
    @GetMapping("findLatelyList")
    public R findLatelyList() {
        List<LiveCourseVo> liveCourseVoList = liveCourseService.findLatelyList();
        return R.ok(liveCourseVoList);
    }
}

